package com.kurumi.medical.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.kurumi.medical.pojo.PointsStandard;
import com.kurumi.medical.query.BasicDataQuery;
import com.kurumi.medical.service.PointsStandardService;
import com.kurumi.medical.util.Result;

@Controller
@RequestMapping("/pointStandard")
public class PointsStandardController {
	
	@Autowired
	private PointsStandardService pointsStandardService;
	
	@RequestMapping("/getPointStandards")
	public String getPointStandards(Model model,BasicDataQuery params){
		List<PointsStandard> basics = pointsStandardService.getPointsStands(params);
		int count = pointsStandardService.getCountByParams(params);
		params.setTotalCounts(count);
		model.addAttribute("count",count);
		model.addAttribute("basics", basics);
		model.addAttribute("basicDataQuery", params);
		return "basic/pointstandards";
	}
	
	@RequestMapping("/addpointStandardPage")
	public String addpointStandardPage(Model model,String tableName){
		return "basic/addpointstandard";
	}
	
	@ResponseBody
	@RequestMapping("/insertPointStandard")
	public Result insertPointStandard(PointsStandard basic){
		if (basic != null) {
			int result = pointsStandardService.insert(basic);
			if (result > 0) {
				return new Result(true, "新增信息成功");
			}
		}
		return new Result(false, "新增信息失败");
	}
	
	
	@RequestMapping("/showPointStandard")
	public String showPointStandard(Model model,Integer id,String name, Integer currentPage,Integer pageSize){
		List<Map<String,Object>> pointStandard = pointsStandardService.selectByPrimaryKey(id);
		model.addAttribute("basic", pointStandard);
		model.addAttribute("name",name);
		model.addAttribute("currentPage", currentPage);
		model.addAttribute("pageSize", pageSize);
		return "basic/updatepointstandard";
	}
	
	@ResponseBody
	@RequestMapping("/updatePointStandard")
	public Result updatePointStandard(PointsStandard basic){
		if (basic != null) {
			int result = pointsStandardService.updateByPrimaryKey(basic);
			if (result > 0) {
				return new Result(true, "修改信息成功");
			}
		}
		return new Result(false, "修改信息失败");
	}

	@ResponseBody
	@RequestMapping("/deletePointStandard")
	public Result deletePointStandard(Integer id){
		int result = pointsStandardService.deleteByPrimaryKey(id);
		if (result > 0) {
			return new Result(true, "删除信息成功");
		} else {
			return new Result(false, "删除信息失败");
		}
	}
}
